package com.dsa.linear;

/**
 *
 * @param <E>
 */
public class ArrayQueue<E> implements Queue<E> {

    private Array<E> data;

    public ArrayQueue() {
        data = new Array<>();
    }

    @Override
    public void enQueue(E element) {
        data.addLast(element);
    }

    @Override
    public E deQueue() {
        return data.removeFirst();
    }

    @Override
    public E head() {
        return data.getFirst();
    }

    @Override
    public int size() {
        return data.size();
    }

    @Override
    public boolean isEmpty() {
        return data.isEmpty();
    }


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("ArrayQueue(size = %d)\n", data.size()));
        sb.append("  head [");
        for (int i = 0; i < data.size(); i++) {
            sb.append(data.get(i));
            if (i != data.size() - 1)
                sb.append(", ");
        }
        sb.append("] tail");
        return sb.toString();
    }
}
